
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgcodecs/legacy/constants_c.h"
#include "opencv2/imgproc/types_c.h"
using namespace cv;
using namespace std;
#include "rgba_to_greyscale.h"


static void onCallbackFun(int height, int width, unsigned char *h_greyImage)
{
    string output_file = "out.png"; 
    cv::Mat outImage(height, width, CV_8UC1, (void *)h_greyImage);
    cv::imwrite(output_file, outImage);
}

int main()
{
    string input_file = "src.png";  
    string output_file = "out.png"; 

    cv::Mat imageRGBA;
    //读取image
    cv::Mat image = cv::imread(input_file, CV_LOAD_IMAGE_COLOR);
    if (image.empty())
    {
        cerr << "读取照片失败：" << input_file << endl;
        exit(1);
    }
    //将BGR转换成RGB
    cv::cvtColor(image, imageRGBA, CV_BGR2RGBA);

    rgba_to_greyscale(imageRGBA.rows, imageRGBA.cols, imageRGBA.ptr<unsigned char>(0), onCallbackFun);
 
    return 0;
}
